package com.isb.emailclient.model;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SimpleMail {
	private int id;
	private String fromAddress;
	private List<String> toAddress = new ArrayList<String>();
	private String subject;
	private String body;
	private Date date;
	
	private List<String> attachmentFileNames = new ArrayList<String>();
	
	private long timeOneDay = 24*60*60*1000; 
	private SimpleDateFormat sdfDate = new SimpleDateFormat("dd/MM");
	private SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm");
	
	
	public SimpleMail() {
	}
	
	
	public SimpleMail(String fromAddress, List<String> toAddress, String subject, String body, Date dateReceive) {
		this.fromAddress = fromAddress;
		this.toAddress = toAddress;
		this.setSubject(subject);
		this.setBody(body);
		this.setDate(dateReceive);
	}
	
	public String getFromAddress() {
		return this.fromAddress;
	}
	
	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}
	
	public List<String> getToAddress() {
		return this.toAddress;
	}
	
	public void setToAddress(List<String> toAddress) {
		this.toAddress = toAddress;
	}
	

	
	public String parseToRecipients() {
		if (this.toAddress.size() > 1) {
			StringBuilder builder = new StringBuilder();
			for (String recipient : this.toAddress) {
				builder.append(recipient);
				builder.append(",");
			}
			return builder.toString().substring(0, builder.toString().length() - 1);
		} else {
			return this.toAddress.get(0);
		}
		
	}

	public String getDateRender() {
		if ((System.currentTimeMillis() - date.getTime()) > timeOneDay)
			return sdfDate.format(date);
		else 
			return sdfTime.format(date);
	}

	public List<String> getAttachmentFileNames() {
		return attachmentFileNames;
	}

	public void setAttachmentFileNames(List<String> attachmentFileNames) {
		this.attachmentFileNames = attachmentFileNames;
	}


	public String getSubject() {
		return subject;
	}


	public void setSubject(String subject) {
		this.subject = subject;
	}


	public String getBody() {
		return body;
	}


	public void setBody(String body) {
		this.body = body;
	}


	public Date getDate() {
		return date;
	}


	public void setDate(Date date) {
		this.date = date;
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}
}
